/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div class="item-title">
      <div class="subject">
        <h3>商家汇款记录</h3>
        <h5>网站系统商家汇款索引与管理</h5>
      </div>
      <ul class="tab-base nc-row">
        <router-link
          :to="{name:'store_remittance_list'}"
          :active-class="status == 1 ? 'current' : ''"
        >
          <li @click="status = 1;currentPage = 1;getPage()">
            <a>
              <span>待转账列表</span>
            </a>
          </li>
        </router-link>
        <router-link
          :to="{name:'store_remittance_list'}"
          :active-class="status == 2 ? 'current' : ''"
        >
          <li @click="status = 2;currentPage = 1;getPage()">
            <a>
              <span>已转账列表</span>
            </a>
          </li>
        </router-link>
      </ul>
    </div>
    <div
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>支付宝，微信在线转账会接收到付款成功通知，自动完成转账，银行卡转账则需要手动确认完成</li>
          <li>支付宝，微信支付接口支持在线向用户付款完成转账，银行卡提现请通过网银在线转账或者其他方式处理</li>
          <li>手动完成转账是指通过银行打款或其他转款方式处理了该笔提现申请，手动这一步操作只是标示该申请提现流程已处理完</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>

    <div class="mDiv">
      <div class="ftitle">
        <h3>商家汇款记录列表</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <div class="fbutton">
        <div class="add" @click="remittanceExport()">
          <span>
            <i class="fa fa-share" /> 导出Excel
          </span>
        </div>
      </div>
      <div class="fbutton" v-if="status == 1">
        <div class="add" @click="type = 1;remittanceHandle()">
          <span>
            <i class="el-icon-position" /> 在线完成转账
          </span>
        </div>
      </div>
      <div class="fbutton" v-if="status == 1">
        <div class="add" @click="type = 2;remittanceHandle()">
          <span>
            <i class="el-icon-thumb" /> 手动完成转账
          </span>
        </div>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
      <div class="searchbox">
        <el-date-picker
          size="small"
          v-model="dateRange"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="起始时间"
          end-placeholder="截止时间"
        ></el-date-picker>
        <el-input
          class="searchinput"
          v-model="store_id"
          width="10"
          size="small"
          placeholder="店铺ID"
          clearable
        />
        <el-input
          class="searchinput"
          v-model="realname"
          width="10"
          size="small"
          placeholder="银行账户"
          clearable
        />
        <el-input
          class="searchinput"
          v-model="bank_card"
          width="10"
          size="small"
          placeholder="银行账号"
          clearable
        />
        <el-button
          class="searchbtn"
          size="small"
          icon="el-icon-search"
          @click="currentPage = 1;getPage()"
        >搜索</el-button>
      </div>
    </div>
    <div class="tablebox">
      <el-table :data="tableData" ref="multipleTable" style="width: 100%;">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column label="记录ID" prop="id" width="80"></el-table-column>
        <el-table-column label="店铺ID" prop="store_id" width="80"></el-table-column>
        <el-table-column label="店铺名称" prop="store_name" width="150" show-overflow-tooltip></el-table-column>
        <el-table-column label="银行名称" prop="bank_name" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="银行账号" prop="bank_card" width="180"></el-table-column>
        <el-table-column label="银行账户" prop="realname" width="100"></el-table-column>
        <el-table-column label="申请金额" prop="money" width="100"></el-table-column>
        <el-table-column label="状态" prop="status_desc" width="80"></el-table-column>
        <el-table-column label="操作时间" width="150">
          <template slot-scope="scope">{{scope.row.create_time | datefmtYMDHM}}</template>
        </el-table-column>
        <el-table-column label="备注" prop="remark" width="200" show-overflow-tooltip></el-table-column>
        <el-table-column label="操作" v-if="status == 1">
          <template slot-scope="scope">
            <el-button-group>
              <el-button
                size="small"
                icon="el-icon-position"
                @click="type = 1;remittanceHandle(scope.row.id)"
              >在线转账</el-button>
              <el-button
                size="small"
                icon="el-icon-thumb"
                @click="type = 2;remittanceHandle(scope.row.id)"
              >手动转账</el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { getStoreWithdrawalsPage } from "@/utils/api";
export default {
  data() {
    return {
      dateRange: null,
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 20,
      store_id: null,
      realname: null,
      bank_card: null,
      status: 1,
      type: 1 //转账方式： 1-在线  2-手动
    };
  },
  created() {
    this.getPage();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      var params = {
        page: this.currentPage,
        size: this.pageSize,
        status: this.status,
        store_id: this.store_id,
        realname: this.realname,
        bank_card: this.bank_card
      };
      if (this.dateRange) {
        params.start_time = this.dateRange[0] / 1000;
        params.end_time = this.dateRange[1] / 1000 + 86400;
      }
      getStoreWithdrawalsPage(params).then(function(res) {
        that.tableData = res.records;
        that.totalCount = res.total;
      });
    },
    remittanceExport() {
      //获取选中的记录
      var ids = this.getSelection();
      //拼接参数
      var paramsStr = "s=1";
      if (ids.length > 0) {
        paramsStr += "&ids=" + ids.join(",");
      } else {
        if (this.store_id != null && this.store_id !== "") {
          paramsStr += "&store_id=" + this.store_id;
        }
        if (this.realname != null && this.realname !== "") {
          paramsStr += "&realname=" + this.realname;
        }
        if (this.bank_card != null && this.bank_card !== "") {
          paramsStr += "&bank_card=" + this.bank_card;
        }
        if (this.status != null && this.status !== "") {
          paramsStr += "&status=" + this.status;
        }
        if (this.dateRange) {
          paramsStr +=
            "&start_time=" +
            this.dateRange[0] / 1000 +
            "&end_time=" +
            (this.dateRange[1] / 1000 + 86400);
        }
      }
      window.location.href = "seller/store_withdrawals/export?" + paramsStr;
    },
    remittanceHandle(id) {
      // if (type == 1) {
      //   //在线完成转账
      // } else {
      //   //手动完成转账
      // }
      this.$message.info("施工中...");
    },
    refresh() {
      this.currentPage = 1;
      this.getPage();
      this.$message.success("刷新成功！");
    },
    getSelection() {
      var rows = this.$refs.multipleTable.selection;
      var ids = [];
      rows.forEach(e => {
        ids.push(e.id);
      });
      return ids;
    }
  }
};
</script>

<style scoped>
.searchinput {
  width: auto;
}
.searchbox {
    width: 52%;
    height: 46px;
    text-align: right;
    box-sizing: border-box;
    float: right;
	border-bottom: 0px solid #ddd;
}
>>>.el-range-editor.el-input__inner {
    display: -webkit-inline-box;
    display: -ms-inline-flexbox;
    display: inline-flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    padding: 3px 10px;
    width: 280px;
}
>>>.el-input--small .el-input__inner {
    height: 32px;
    line-height: 32px;
    width: 105px;
}
</style>
